package top.pcat.config;

import lombok.Data;
import top.pcat.Server;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Zookeeper配置处理
 */
@Data
public class ZookeeperConfig{

    private String connectString;
    private int sessionTimeoutMs;
    private int connectionTimeoutMs;
    private int baseSleepTimeMs;
    private int maxRetries;
    private String devicePath;

    public ZookeeperConfig() throws IOException {
        InputStream inputStream = Server.class.getClassLoader().getResourceAsStream("server.properties");
        Properties properties = new Properties();
        properties.load(inputStream);

        this.connectString = properties.getProperty("zookeeper.connectString");
        this.sessionTimeoutMs = Integer.parseInt(properties.getProperty("zookeeper.sessionTimeoutMs"));
        this.connectionTimeoutMs = Integer.parseInt(properties.getProperty("zookeeper.connectionTimeoutMs"));
        this.baseSleepTimeMs = Integer.parseInt(properties.getProperty("zookeeper.retryPolicy.baseSleepTimeMs"));
        this.maxRetries = Integer.parseInt(properties.getProperty("zookeeper.retryPolicy.maxRetries"));
        this.devicePath = properties.getProperty("zookeeper.devicePath");
    }

}
